package com.example.springboot09.shejimoshi;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * @ClassName 建造者模式
 * @Description TODO
 * @Author tianqinglong
 * @Date 14:42 2022/7/25
 * @Version 1.0
 **/
public class 建造者模式 {
    public static void main(String[] args) {
        //指挥
        Director director = new Director();
        //指挥 具体的工人完成  产品
        Product build = director.build(new Worker());
        //顺序由工人决定
        System.out.println(build.toString());
    }
}
//抽象的建造者
abstract class Builder {
    abstract void buildA();//地基
    abstract void buildB();//钢筋工程
    abstract void buildC();//铺电线
    abstract void buildD();//粉刷

    //完工 ：得到产品
    abstract Product getProduct();
}
//@Data
//@AllArgsConstructor
//@NoArgsConstructor
//@ToString
//产品： 房子
class Product {
    private String buildA;
    private String buildB;
    private String buildC;
    private String buildD;

    @Override
    public String toString() {
        return "Product{" +
                "buildA='" + buildA + '\'' +
                ", buildB='" + buildB + '\'' +
                ", buildC='" + buildC + '\'' +
                ", buildD='" + buildD + '\'' +
                '}';
    }

    public String getBuildA() {
        return buildA;
    }

    public void setBuildA(String buildA) {
        this.buildA = buildA;
    }

    public String getBuildB() {
        return buildB;
    }

    public void setBuildB(String buildB) {
        this.buildB = buildB;
    }

    public String getBuildC() {
        return buildC;
    }

    public void setBuildC(String buildC) {
        this.buildC = buildC;
    }

    public String getBuildD() {
        return buildD;
    }

    public void setBuildD(String buildD) {
        this.buildD = buildD;
    }
}
//具体的建造者
class Worker extends Builder {
    private Product product;

    public Worker(){
        product=new Product();
    }
    @Override
    void buildA() {
        product.setBuildA("地基");
        System.out.println("地基");
    }

    @Override
    void buildB() {
        product.setBuildB("钢筋工程");
        System.out.println("钢筋工程");
    }

    @Override
    void buildC() {
        product.setBuildB("铺电线");
        System.out.println("铺电线");
    }

    @Override
    void buildD() {
        product.setBuildB("粉刷");
        System.out.println("粉刷");
    }

    @Override
    Product getProduct() {
        return product;
    }
}
//指挥者
class Director {
    //指挥工人按照顺序建房子
    public Product build(Builder builder){
        builder.buildA();
        builder.buildB();
        builder.buildC();
        builder.buildD();
        return builder.getProduct();
    }
}
